package com.zr.task.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.TextView;

import com.zr.task.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


/**
 * Created by Administrator on 2018/3/27.
 */

public class ChooseDialog extends Dialog {
    @BindView(R.id.text_hint)
    TextView textHint;
    private String hint;
    private OnClickListener onClickListener = null;


    public ChooseDialog( Context context, int themeResId, String hint, OnClickListener onClickListener) {
        super(context, themeResId);
        this.onClickListener = onClickListener;
        this.hint = hint;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_choose);
        ButterKnife.bind(this);

        //设置不可取消，点击其他区域不能取消
        setCancelable(false);
        setCanceledOnTouchOutside(false);
        textHint.setText(hint);

    }

    @OnClick({R.id.btn_cancel, R.id.btn_confirm})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_cancel:
                this.cancel();
                break;
            case R.id.btn_confirm:
                this.cancel();
                if (onClickListener != null) {
                    onClickListener.onClick(view, this);
                }
                break;
        }
    }
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
            this.cancel();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    public interface OnClickListener {
        void onClick(View view, Dialog dialog);
    }
}
